import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import dayjs from 'dayjs';
// import { getNewDate } from '/@/api/travelItinerary/getDateAPI';

export const columns: BasicColumn[] = [
  //2
  {
    title: '终端类型',
    dataIndex: 'linkman',
    width: 100,
    customRender: ({ text }) => {
      if (text === '票务') {
        return h(Tag, { color: 'green' }, () => 'PC');
      } else {
        return h(Tag, { color: 'green' }, () => 'APP');
      }
    },
  },
  //3
  {
    title: '出票日期',
    dataIndex: 'outTicketDate',
    width: 160,
    customRender: ({ record }) => {
      if (record.outTicketDate) return dayjs(record.outTicketDate).format('YYYY-MM-DD hh:mm:ss');
    },
  },
  //4
  { title: '预定人姓名', dataIndex: 'bookerName', width: 100 },
  //5
  { title: '预定人手机', dataIndex: 'bookerTel', width: 130 },
  //6
  { title: '审批单号', dataIndex: 'exNum', width: 150 },
  //7
  {
    title: '审批出发日期',
    dataIndex: 'dateOfDeparture',
    width: 120,
    customRender: ({ record }) => {
      if (record.dateOfDeparture) return dayjs(record.dateOfDeparture).format('YYYY-MM-DD');
    },
  },
  //8
  {
    title: '审批返回日期',
    dataIndex: 'dateOfReturn',
    width: 120,
    customRender: ({ record }) => {
      if (record.dateOfDeparture) return dayjs(record.dateOfReturn).format('YYYY-MM-DD');
    },
  },
  //9
  { title: '职工编号', dataIndex: 'empNo', width: 80 },
  //10
  { title: 'PNR', dataIndex: 'pnr', width: 80 },
  //11
  { title: '全价', dataIndex: 'cabinAllPrice', width: 90 },
  //12
  { title: '票号', dataIndex: 'tickerNo', width: 140 },
  //13
  { title: '职工姓名', dataIndex: 'empName', width: 90 },
  //14
  { title: '联系手机', dataIndex: 'empTel', width: 130 },
  //15
  { title: '行程', dataIndex: 'voyage', width: 150 },
  //16
  { title: '航班号', dataIndex: 'flightNum', width: 80 },
  //17
  { title: '航空公司', dataIndex: 'carrierName', key: 'carrierName' },
  //18
  {
    title: '出发日期',
    dataIndex: 'deptDate',
    width: 130,
    customRender: ({ record }) => {
      return record.deptDate ? dayjs(record.deptDate).format('YYYY-MM-DD') : '-';
    },
  },
  //19
  { title: '出发时间', dataIndex: 'deptTime', width: 80 },
  //20
  {
    title: '抵达日期',
    dataIndex: 'arriveDate',
    width: 130,
    customRender: ({ record }) => {
      return record.arriveDate ? dayjs(record.arriveDate).format('YYYY-MM-DD') : '-';
    },
  },
  //21
  { title: '抵达时间', dataIndex: 'arriveTime', width: 80 },
  //22
  { title: '舱位', dataIndex: 'cabinCode', key: 'cabinCode' },
  //23
  { title: '机票价', dataIndex: 'salePrice', key: 'salePrice', width: 90 },
  //24
  { title: '税', dataIndex: 'taxSum', key: 'taxSum', width: 90 },
  //25
  { title: '机票合计金额', dataIndex: 'planePriceSum', key: 'planePriceSum', width: 110 },

  {
    title: '改签费',
    dataIndex: 'a1',
    width: 90,
    customRender: ({ record }) => {
      return record.changeFee + record.changeUpFee;
    },
  },

  //29
  { title: '应退款(含税)', dataIndex: 'refundBeAmount', width: 110 },

  //30
  { title: '保险', dataIndex: 'insurance', key: 'insurance', width: 90 },
  {
    title: '用车',
    dataIndex: 'a3',
    width: 90,
    customRender: () => {
      return 0;
    },
  },
  {
    title: '其它',
    dataIndex: 'a4',
    width: 90,
    customRender: () => {
      return 0;
    },
  },
  //31
  { title: '折扣率', dataIndex: 'agio', key: 'agio', width: 90 },
  //32
  { title: '服务费', dataIndex: 'ticketServicePrice', key: 'ticketServicePrice, width: 90 ' },
  //33
  {
    title: '深白云扣款',
    dataIndex: 'priceBy',
    key: 'priceBy',
    width: 105,
    customRender: ({ record }) => {
      if (record.bookingType == '改期单') return record.changeUpFee + record.changeFee;
      else if (record.bookingType == '退票单')
        return (
          record.refundPrice +
          record.ticketPrice -
          record.insurance +
          (record.changeUpFee + record.changeFee)
        );
      else return record.ticketPrice + record.insurance;
    },
  },

  //34
  { title: '退票费(财务)', dataIndex: 'refundPrice', width: 105 },
  //35
  {
    title: '应收',
    dataIndex: 'ticketPrice',
    key: 'ticketPrice',
    width: 90,
    customRender: ({ record }) => {
      if (record.bookingType == '改期单') return record.changeUpFee + record.changeFee;
      else if (record.bookingType == '退票单')
        return (
          record.refundPrice +
          record.ticketPrice -
          record.insurance +
          (record.changeUpFee + record.changeFee)
        );
      else return record.ticketPrice + record.insurance;
    },
  },
  //36
  {
    title: '总金额包含服务费',
    dataIndex: 'ticketPriceSum',
    key: ' ticketPriceSum',
    width: 130,
    customRender: ({ record }) => {
      if (record.bookingType == '改期单')
        return record.changeUpFee + record.changeFee + record.ticketServicePrice;
      else if (record.bookingType == '退票单')
        return (
          record.refundPrice +
          record.ticketPriceSum +
          record.changeUpFee +
          record.changeFee +
          record.insurance
        );
      else return record.ticketPriceSum + record.insurance;
    },
  },
  {
    title: '订票方式',
    dataIndex: 'a5',
    customRender: () => {
      return '无审批单';
    },
  },
  //37
  {
    title: '结算',
    width: 90,
    dataIndex: 'isSettlement',
    customRender: ({ text }) => {
      if (text === 0) {
        return h(Tag, { color: 'red' }, () => '未结算');
      } else if (text === 1) {
        return h(Tag, { color: 'green' }, () => '已结算');
      }
    },
  },
  //38
  {
    title: '白云对帐',
    width: 90,
    dataIndex: 'isAccount',
    customRender: ({ text }) => {
      if (text === 0) {
        return h(Tag, () => '未对帐');
      } else if (text === 1) {
        return h(Tag, { color: 'red' }, () => '已对帐');
      }
    },
  },
  //39
  {
    title: '支付时间',
    dataIndex: 'payDate',
    customRender: ({ record }) => {
      return record.payDate ? dayjs(record.payDate).format('YYYY/MM/DD') : '-';
    },
  },
  //40
  { title: '订票类型', dataIndex: 'bookingType', width: 90 },

  //41
  { title: '机票类型', dataIndex: 'belongType', width: 90 },
  //42
  {
    title: '备注',
    dataIndex: 'remark',
    customRender: ({ record }) => {
      if (record.remark) return record.remark;
      else return '-';
    },
  },
  //43
  { title: '身份证号', dataIndex: 'empIdNum', width: 180 },
  {
    title: '消费记录id',
    dataIndex: 'a12',
    customRender: ({ record }) => {
      return record.id;
    },
  },
  // {
  //   title: '订单号',
  //   dataIndex: 'a13',
  //   width: 190,
  //   customRender: ({ record }) => {
  //     return record.orderNum;
  //   },
  // },
  {
    title: '乘机人卡号',
    dataIndex: 'a14',
    width: 160,
    customRender: ({ record }) => {
      return record.empIdNum;
    },
  },
  {
    title: '出发城市',
    dataIndex: 'a15',
    customRender: ({ record }) => {
      return record.orgName;
    },
  },
  {
    title: '到达地',
    dataIndex: 'a16',
    customRender: ({ record }) => {
      return record.dstName;
    },
  },
  {
    title: '员工部门',
    dataIndex: 'a17',
    width: 100,
    customRender({ record }) {
      return record.departmentId ? record.departmentId : '-';
    },
  },
  {
    title: '订单号',
    dataIndex: 'a70',
    width: 190,
    customRender({ record }) {
      return record.orderNum;
    },
  },
];
export const searchFormSchema: FormSchema[] = [
  {
    field: 'outTicketDate',
    component: 'RangePicker',
    label: '出票日期',
    colProps: {
      span: 5,
    },
    componentProps: {
      placeholder: ['出票时间起', '出票时间止'],
      style: 'width: 230px',
    },
    defaultValue: [getCurrentDataL(), getCurrentDataR()],
  },
  {
    field: 'deptDate',
    component: 'RangePicker',
    label: '起飞日期',
    colProps: {
      span: 5,
    },
    componentProps: {
      placeholder: ['起飞日期起', '起飞日期止'],
      style: 'width: 230px',
    },
    // defaultValue: [getCurrentDataL(), getCurrentDataR()],
  },
  {
    field: 'empNo',
    label: '职工编号',
    component: 'Input',
    colProps: { span: 4 },
    componentProps: {
      placeholder: '职工编号',
      style: 'width: 160px',
      align: 'center',
    },
  },
  {
    field: 'empName',
    label: '职工姓名',
    component: 'Input',
    colProps: { span: 4 },
    componentProps: {
      placeholder: '职工姓名',
      style: 'width: 160px',
      align: 'center',
    },
  },
  // {
  //   field: 'cabinCode',
  //   label: '舱位:',
  //   component: 'Input',
  //   colProps: { span: 2 },
  //   componentProps: {
  //     placeholder: ' ',
  //     // style: 'width: 110px',
  //   },
  // },
  {
    field: 'flightNum',
    label: '航班号',
    component: 'Input',
    colProps: { span: 4 },
    componentProps: {
      placeholder: '航班号',
      style: 'width: 160px',
    },
  },
  {
    field: 'bookingType',
    label: '订票类型',
    component: 'Select',
    colProps: { span: 5 },
    componentProps: {
      style: 'width: 230px',
      placeholder: '请选择审批单状态',
      // style: 'width: 180px',
      options: [
        { label: '出票单', value: '出票单' },
        { label: '改期单', value: '改期单' },
        { label: '退票单', value: '退票单' },
      ],
    },
  },
  {
    field: 'tickerNo',
    label: '票号',
    component: 'Input',
    colProps: { span: 5 },
    componentProps: {
      placeholder: '票号',
      style: 'width: 230px',
    },
  },
  {
    field: 'orgName',
    label: '出发城市',
    component: 'Input',
    colProps: { span: 4 },
    componentProps: {
      placeholder: '出发城市',
      style: 'width: 160px',
    },
  },
  {
    field: 'dstName',
    label: '到达城市',
    component: 'Input',
    colProps: { span: 4 },
    componentProps: {
      placeholder: '到达城市',
      style: 'width: 160px',
    },
  },
  // {
  //   field: 'optDateStart',
  //   label: ' 操作时间',
  //   component: 'Select',
  //   colProps: { span: 8 },
  //   defaultValue: getNewDate('before', 1),
  //   componentProps: {
  //     allowClear: false,
  //     style: 'width: 150px',
  //     options: [
  //       { label: '近1个月内数据', value: getNewDate('before', 1) },
  //       { label: '近3个月内数据', value: getNewDate('before', 3) },
  //       { label: '近半年内数据', value: getNewDate('before', 6) },
  //       { label: '近一年内数据', value: getNewDate('before', 12) },
  //     ],
  //   },
  // },
];

//获得当前年份4位年
function getCurrentDataL() {
  return dayjs(dayjs().year().toString() + '-' + Number(dayjs().month()) + '-15').format(
    'YYYY-MM-DD',
  );
}
function getCurrentDataR() {
  // return new Date().toLocaleDateString();
  return dayjs(dayjs().year().toString() + '-' + Number(dayjs().month() + 1) + '-16').format(
    'YYYY-MM-DD',
  );
}
